<template>
  <div>
    <el-breadcrumb separator=">" style="font-size: 20px">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/">黑名单</a></el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>


    <el-form :inline="true" class="user-search">
      <el-form-item label="搜索">
        <el-input size="small" v-model="cardId" placeholder="输入姓名"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="sel()">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table
        :data="tableData"
        style="width: 100%"
        :default-sort="{prop: 'date', order: 'descending'}"
    >
      <el-table-column prop="id" label="编号" header-align="center" align="center" width="180"></el-table-column>
      <el-table-column prop="carId" sortable label="车牌" header-align="center" align="center"
                       width="180"></el-table-column>
      <el-table-column prop="createTime" header-align="center" align="center" label="时间"></el-table-column>
      <el-table-column prop="connect" header-align="center" align="center" label="原因"></el-table-column>
      <el-table-column label="操作" header-align="center" align="center">
        <template slot-scope="scope">
          <el-button @click="del(scope.row)" style="background-color: #0096dc"  size="small">移除</el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      cardId: ''
    };
  },
  methods: {
    del(row) {

      let url = 'http://localhost:8080/black/delete?id=' + row.id
      console.log(url)
      this.axios
          .create({'headers': {'Authorization': localStorage.getItem('jwt')}})
          .get(url).then((respone) => {
        let responseBody = respone.data
        if (responseBody.code == 200) {
          this.$message({
            showClose: true,
            message: "移除黑名单成功",
            type: 'success'
          });
          this.loadBlackList()
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });

    },
    sel() {
      let url = 'http://localhost:8080/black/search?carId=' + this.cardId
      console.log(url)
      this.axios
          .create({'headers': {'Authorization': localStorage.getItem('jwt')}})
          .get(url).then((respone) => {
        let responseBody = respone.data
        if (responseBody.code == 200) {
          this.tableData = responseBody.data;
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });

    },
    loadBlackList() {
      let url = 'http://localhost:8080/black/getList'
      this.axios
          .create({'headers': {'Authorization': localStorage.getItem('jwt')}})
          .get(url).then((respone) => {
        let responseBody = respone.data
        if (responseBody.code == 200) {
          this.tableData = responseBody.data;
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });
    }
  },
  created() {
    this.loadBlackList()
  }
}
</script>
